/**
 * Created by admin on 2018/1/5.
 */
import {config, sandBox} from '../../../lib/myapp.js'
Page({

    data: {
        activeIndex: 0,
        sliderOffset: 0,
        sliderLeft: 0,
        width: 0,
        tabList: [
            {
                title: "申请售后",
                init: false,
                page: 0,
                more: false,
                show: false
            },
            {
                title: "进度查询",
                init: false,
                page: 0,
                more: true,
                show: false
            },
        ],
        orderData: {},
        orderId: ''
    },
    onLoad(){

    },


    onShow(){
        wx.getSystemInfo({
            success: res => {
                this.setData({
                    width: res.windowWidth / this.data.tabList.length,
                    sliderOffset: res.windowWidth / this.data.tabList.length * this.data.activeIndex
                })
            }
        });
    },
    search(){
        var oauth = wx.getStorageSync('user_token');
        wx.showLoading({
            mask:true
        })
        sandBox.get({
            api: 'api/O2O/order/list',
            data: {
                order_no: this.data.orderId
            },
            header: {Authorization: oauth},
        }).then(res => {
            if (res.statusCode === 200) {
                if (res.data) {
                    this.setData({
                        orderData: res.data.data[0]
                    })
                } else {
                    wx.showModal({
                        content: '暂无该订单数据',
                        showCancel: false
                    })
                }
            }

            wx.hideLoading()
        }).catch(() => {
            wx.showModal({
                content: '服务端错误',
                showCancel: false
            })
            wx.hideLoading()
        })
    },
    changeValue(e){
        var value = e.detail.value;
        this.setData({
            orderId: value
        })
    },
    toDetail(e){
        var order_no = e.currentTarget.dataset.orderno;
        var index = e.currentTarget.dataset.index
        var data = this.data.orderData;
        if (order_no) {
            wx.navigateTo({
                url: `/pages/afterSales/detail/detail?order_no=${order_no}`,
                success(){
                    wx.setStorageSync('afterSale',data.items[index])
                }
            })
        } else {
            wx.showModal({
                content:'缺少订单号',
                showCancel:false
            })
        }
    },
    tabClick(e) {

        var status = e.currentTarget.id;
        this.setData({
            sliderOffset: e.currentTarget.offsetLeft,
            activeIndex: status
        });
        // if (!this.data.tabList[status].init) {
        //     wx.showLoading({
        //         title: "加载中",
        //         mask: true
        //     });
        //
        //     // this.queryOrderList(status, 1, this.data.owner);
        // }
    },


})